package com.gexin.model.activity;

import com.gexin.model.activity.base.BaseReverseMultipleRule;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import static com.gexin.common.utils.ArithUtil.percent;
import static com.gexin.common.utils.ArithUtil.percentt;

/**
 * 业务名称:  t_reverse_multiple_rule() 
 */
@SuppressWarnings("serial")
public class ReverseMultipleRule extends BaseReverseMultipleRule<ReverseMultipleRule> {
	public static final ReverseMultipleRule dao = new ReverseMultipleRule();

	public List<ReverseMultipleRule> getReverseMultipleRule(){
		List<ReverseMultipleRule> reverseMultipleRuleList=ReverseMultipleRule.dao.find("select * from t_reverse_multiple_rule");
		return reverseMultipleRuleList;
	}
	public static Boolean insertReverseMultipleRule(String reverse_multiple_min, String reverse_multiple_max, String reverse_multiple_count_min, String reverse_multiple_count_max) {
		ReverseMultipleRule reverseMultipleRule = new ReverseMultipleRule();
		BigDecimal reverseMultipleMin= BigDecimal.valueOf(percent(Integer.parseInt(reverse_multiple_min),100));
		BigDecimal reverseMultipleMax= BigDecimal.valueOf(percent(Integer.parseInt(reverse_multiple_max),100));
		BigDecimal reverseMultipleCountMin= BigDecimal.valueOf(percentt(Double.parseDouble(reverse_multiple_count_min),1));
		BigDecimal reverseMultipleCountMax= BigDecimal.valueOf(percentt(Double.parseDouble(reverse_multiple_count_max),1));
		reverseMultipleRule.setId(UUID.randomUUID().toString());
		reverseMultipleRule.setReverseMultipleMin(reverseMultipleMin);
		reverseMultipleRule.setReverseMultipleMax(reverseMultipleMax);
		reverseMultipleRule.setReverseMultipleCountMin(reverseMultipleCountMin);
		reverseMultipleRule.setReverseMultipleCountMax(reverseMultipleCountMax);
		reverseMultipleRule.setStatus(1);
		long time = new Date().getTime();
		reverseMultipleRule.setCreateTime(time);
		reverseMultipleRule.setUpdateTime(time);
		Boolean flag = false;
		flag = reverseMultipleRule.save();
		return flag;
	}

	public static Boolean deleteReverseMultipleRule(String id){
		return ReverseMultipleRule.dao.deleteById(id);
	}


	public ReverseMultipleRule getReverse(){
		return ReverseMultipleRule.dao.findFirst("select * from t_reverse_multiple_rule");
	}


	public BigDecimal reverseMultiple = this.getIncrementMultiple()==null?new BigDecimal("0"):this.getIncrementMultiple();
}
